package com.hk.blog.controller;

import com.hk.core.web.Webs;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Kevin
 * @date 2022-06-27 8:32
 */
@Controller
@RequestMapping("images")
public class ImageController {

    @RequestMapping("{name:.+}")
    public ResponseEntity<?> image(@PathVariable String name) throws Exception {
        ClassPathResource resource = new ClassPathResource("images/" + name);
        return Webs.toResponseEntity(resource.getFile(), false);
    }
}
